package org.zwt.common.enumerate;

import lombok.NoArgsConstructor;
@NoArgsConstructor
public enum ResponseStatus {
    OK(200, "OK"),
    METHOD_SERVER_ERROR(500,"Internal Server Error");

    private int code;
    private String text;

    ResponseStatus(int code, String text){
        this.code = code;
        this.text = text;
    }

    public static ResponseStatus fromCode(int code){
        for(ResponseStatus status : ResponseStatus.values()){
            if(status.getCode() == code){
                return status;
            }
        }
        return null;
    }

    public static ResponseStatus fromCode(String code){
        int c= Integer.parseInt(code);
        return fromCode(c);
    }
    public static ResponseStatus fromText(String text){
        for(ResponseStatus status : ResponseStatus.values()){
            if(status.text.equalsIgnoreCase(text)){
                return status;
            }
        }
        return null;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Override
    public String toString() {
        return this.code + " " + this.text;
    }
}
